package dgcptic.interventions;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mortbay.jetty.servlet.Dispatcher;

import dgcptic.interventions.model.Demande;
import dgcptic.interventions.model.DemandeFactory;

public class ServletEnregistrementDemande extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		String titre = req.getParameter("titre");
		String description=req.getParameter("description");

		Demande demand = new Demande();
		demand.setId(""+new Date());
		demand.setTitre(titre);
		demand.setDescription(description);

		DemandeFactory dfactory = new DemandeFactory();
		dfactory.persists(demand);
		DemandeFactory df = new DemandeFactory();
		List<Demande> demandes = df.getListDemandes();
		req.setAttribute("DEMANDES", demandes);
		req.setAttribute("comment", "il y a "+demandes.size()+" demandes");
		RequestDispatcher dispatcher = this.getServletContext()
				.getRequestDispatcher("/afficherdemande2.jsp");
		dispatcher.forward(req, resp);

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}
	
	

}
